package com.atguigu.tingshu.live.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.live.service.LiveRoomService;
import com.atguigu.tingshu.model.live.LiveRoom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/live/liveRoom")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LiveRoomApiController {

	@Autowired
	private LiveRoomService liveRoomService;

	@GuiGuLogin
	@GetMapping(value = "/getCurrentLive" )
	public Result<LiveRoom> getCurrentLive() {
		LiveRoom liveRoom = liveRoomService.getCurrentLive();
		return Result.build(liveRoom , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin
	@PostMapping(value = "/saveLiveRoom")
	public Result<LiveRoom> saveLiveRoom(@RequestBody LiveRoom liveRoom) {
		LiveRoom dbLiveRoom = liveRoomService.saveLiveRoom(liveRoom) ;
		return Result.build(dbLiveRoom , ResultCodeEnum.SUCCESS) ;
	}

	@GetMapping(value = "/getById/{id}")
	public Result<LiveRoom> getById(@PathVariable(value = "id") Long liveRoomId) {
		LiveRoom liveRoom = liveRoomService.getById(liveRoomId);
		return Result.build(liveRoom , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin
	@GetMapping(value = "/findLiveList")
	public Result<List<LiveRoom>> findLiveList() {
		List<LiveRoom> liveRoomList = liveRoomService.findLiveList() ;
		return Result.build(liveRoomList , ResultCodeEnum.SUCCESS) ;
	}
}

